package com.mvp.shq.washer.wxapi;







import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.mvp.shq.washer.R;
import com.mvp.shq.washer.rxbus.RxBus;
import com.mvp.shq.washer.utils.EventCode;
import com.mvp.shq.washer.utils.T;
import com.orhanobut.logger.Logger;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
	
	private static final String TAG = "MicroMsg.SDKSample.WXPayEntryActivity";
	private final String APP_ID = "wx18074b4c6adce3f8";
	
    private IWXAPI api;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pay_result);
    	api = WXAPIFactory.createWXAPI(this, APP_ID);
        api.handleIntent(getIntent(), this);
    }

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
        api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq req) {
	}

	@Override
	public void onResp(BaseResp resp) {
        switch (resp.errCode){
            case 0:
                //支付成功
               T.show("支付成功");
                RxBus.get().send(EventCode.GET_USER_INFO);
                RxBus.get().send(EventCode.ORDER_PAY_SUCCESS);
                RxBus.get().send(EventCode.SHOP_PAY_SUCCESS);
                finish();
                break;
            case -1:
                //错误
                T.show("支付错误");
                finish();
                break;
            case -2:
                //用户取消
                T.show("取消支付");
                finish();
                break;
        }
//		if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
//			AlertDialog.Builder builder = new AlertDialog.Builder(this);
//			builder.setTitle(R.string.app_tip);
//			builder.setMessage(getString(R.string.pay_result_callback_msg, String.valueOf(resp.errCode)));
//			builder.show();
//		}
	}
}